<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\model\UserNotify;
use app\common\tool\Result;
use think\Response;

class Notify extends Base
{
    public function index(): Response
    {
        $map = ['uid' => $this->user->id];

        return Result::fastReturn(UserNotify::getPageList($map, 'id,title,create_time',
            $this->getPage(), $this->getLimit(), false));
    }

    public function info($id): Response
    {
        $info = UserNotify::where(['id' => $id])
            ->field('id,title,content,status,create_time')->find();
        if (!$info) {
            return Result::fail('通知不存在');
        }
        $info->content = handleRichText($info->content);
        if ($info->status == 0) {
            $info->status = 1;
            $info->save();
        }

        return Result::success('success', $info);
    }
}